<template>
  <div class="home">
    <!-- 顶部背景 -->
    <div class="top-bg">
      <div class="mask"></div>
      <img src="../assets/1013_bg.jpg" alt="西餐厅" />

      <fragment-details></fragment-details>
    </div>
    <!-- 一级横向nav标签页 -->
    <nav class="nav-row-box">
      <div class="tab-row">
        <van-tabs v-model="active" color="#649cba" line-width="25">
          <van-tab title="商品"></van-tab>
          <van-tab title="评论"></van-tab>
          <van-tab title="详情"></van-tab>
        </van-tabs>
      </div>
      <div class="my-orderForm" @click="checkOrderForm">
        <van-icon name="bill-o" color="#d38444" />
        我的订单
      </div>
    </nav>
    <div class="tab-content">
      <keep-alive>
        <component :is="activeTabContent"></component>
      </keep-alive>
    </div>

    <van-tabbar v-model="active_tab" route>
      <van-tabbar-item icon="home-o" to="/">Home</van-tabbar-item>
      <van-tabbar-item icon="contact" to="/my">My</van-tabbar-item>
    </van-tabbar>
  </div>
</template>

<script>
import myDetails from "@/components/home/my-details.vue";
import myComment from "@/components/home/my-comment.vue";
// import goodsList from "@/components/home/goods-list.vue";
import goodsList2 from "@/components/home/goods-list2.vue";
import fragmentDetails from "@/components/home/fragment-details.vue";
// import { mapState } from "vuex";

export default {
  name: "Home",
  components: {
    myDetails,
    myComment,
    // goodsList,
    goodsList2,
    fragmentDetails,
  },
  data() {
    return {
      active: 0,
      active_tab: 0,
    };
  },
  methods: {
    checkOrderForm() {
      // console.log("ok");
      this.$router.push("/orderForm");
    },
  },
  computed: {
    // ...mapState("m_tab", ["active_tab"]),
    // 根据tab的active索引切换不同组件
    activeTabContent() {
      let contentArr = ["goodsList2", "myComment", "myDetails"];
      return contentArr[this.active];
    },
  },
};
</script>
<style lang="scss">
.home {
  display: flex;
  flex-direction: column;
  background-color: rgb(247, 247, 247);
  height: calc(100vh - 50px);

  .top-bg {
    position: relative;
    height: 25%;

    .mask {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background-color: rgba(0, 0, 0, 0.3);
    }
  }

  .nav-row-box {
    position: relative;
    display: flex;
    justify-content: space-between;
    height: 7%;
    padding: 0 10px;
    margin: 8px 0 0 0;
    background-color: #fff;

    &::after {
      content: "";
      position: absolute;
      bottom: 0;
      left: 0;
      width: 100%;
      height: 1px;
      background-color: #ccc;
    }

    .tab-row {
      height: 100%;

      .van-tabs {
        height: 100%;

        .van-tabs__wrap {
          height: 100%;
        }
      }
    }

    .van-tab {
      width: 60px;
      color: #747474;
      font-weight: 500;
    }
    .van-tab--active {
      font-weight: 700;
      font-size: 15px;
      color: #000;
    }

    .my-orderForm {
      align-self: center;
      color: #e47105;
      font-weight: 500;
      cursor: pointer;
    }
  }

  .tab-content {
    height: 55%;
    flex-grow: 1;
  }
}
</style>
